package ledrpt

import org.kdx.DateUtils

import java.text.SimpleDateFormat

class DwsScrapController {
    def dynamicQueryService
    def scrapSumList() {
        params.SYS_QUERY_NAME='scrapSumlist'
        def scrapSumlist =dynamicQueryService.queryForList(params)
        [scrapSumlist:scrapSumlist]
    }
    //��ȡ����������Ϣ
    def updateDwsScrap(DwsScrap c){
        render (view:'updateDwsScrap',
                model:[scrap:c])
    }
    //�������޸ĵ���������Ϣ
    def addScrap(DwsScrap cfu){
        cfu.save()
        render """{
                    "statusCode":"200",
                    "message":"${message(code: 'default.created.message', args: [message(code: 'DwsScrap.label', default: 'DwsScrap'), cfu.id])}",
                    "closeCurrent":true,
                    "forward":"",
                    "forwardConfirm":""
                    }"""
    }
    //ɾ������������Ϣ
    def deleteScrap(DwsScrap c){

        c.delete()
        render """{
                    "statusCode":"200",
                    "message":"${message(code: 'default.created.message', args: [message(code: 'DwsScrap.label', default: 'DwsScrap'), c.id])}",
                    "closeCurrent":true,
                    "forward":"",
                    "forwardConfirm":""
                    }"""

    }
    //������ʾ

    def dwsScrapList() {


        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def dayList = DateUtils.getDayList(startTime, endTime)
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def pageSizeList = [10, 20, 50, 100]

        params.SYS_QUERY_NAME = 'dwsScrapList'
        def dataListNo = dynamicQueryService.queryForList(params)

        def totalCount = dataListNo.size()
        params.SYS_QUERY_NAME = 'yieldChartdwsScrap'
        def dataList = dynamicQueryService.queryForList(params)

        def legendDataList = ['QTY']
        //def percentItemList = ['YIELD']
        def seriesData = []
        for(def k=0;k<legendDataList.size();k++){
            def seryHourData = []
            for(def j=0;j<dayList.size();j++){
                def flag = false;
                for(def i=0;i<dataList.size();i++){
                    if(dayList[j]==dataList[i].V_Date){
                        seryHourData.push(dataList[i][legendDataList[k]])
                        flag = true;
                    }
                }
                if(!flag){
                    seryHourData.push(0)
                }
            }
            seriesData.push(seryHourData)
        }
        println seriesData
        def testDataList = []
        [part_name:params.part_name,woId:params.woId,
         startTime:startTime,endTime:endTime,
         scrapPartName:params.scrapPartName?:'',scrapWoId:params.scrapWoId?:'',
         //percentItemList:percentItemList,
         dayList:dayList,legendDataList:legendDataList,seriesData:seriesData,testDataList:testDataList,
         pageSize:pageSize,totalCount:totalCount,pageSizeList:pageSizeList,dataListNo:dataListNo]
    }
}
